package com.ruoyi.bizsys.controller;

import java.util.List;

import com.ruoyi.bizsys.query.AwardActivityQuery;
import com.ruoyi.bizsys.vo.AwardActivityVO;
import com.ruoyi.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bizsys.domain.AwardActivity;
import com.ruoyi.bizsys.service.IAwardActivityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖励活动Controller
 *
 * @author african-loan
 * @date 2022-06-24
 */
@RestController
@RequestMapping("/award/activity")
public class AwardActivityController extends BaseController {
    @Autowired
    private IAwardActivityService awardActivityService;

    /**
     * 查询奖励活动列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwardActivityQuery awardActivityQuery) {
        startPage();
        List<AwardActivityVO> list = awardActivityService.selectAwardActivityList(awardActivityQuery);
        return getDataTable(list);
    }

    /**
     * 获取奖励活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:activity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(awardActivityService.selectById(id));
    }

    /**
     * 新增奖励活动
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('bizsys:activity:add')")
    @Log(title = "奖励活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwardActivityQuery awardActivityQuery) {
        return toAjax(awardActivityService.insertAwardActivity(awardActivityQuery));
    }

    /**
     * 修改奖励活动
     */
    @PreAuthorize("@ss.hasPermi('bizsys:activity:edit')")
    @Log(title = "奖励活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwardActivityQuery awardActivityQuery) {
        return toAjax(awardActivityService.updateAwardActivity(awardActivityQuery));
    }

    /**
     * 启用/停用
     */
    @PreAuthorize("@ss.hasPermi('bizsys:activity:edit')")
    @Log(title = "奖励活动", businessType = BusinessType.UPDATE)
    @PutMapping("/startAndStop")
    public AjaxResult startAndStop(@RequestBody AwardActivityQuery awardActivityQuery) {
        return toAjax(awardActivityService.startAndStop(awardActivityQuery));
    }

    /**
     * 删除奖励活动
     */
    @PreAuthorize("@ss.hasPermi('bizsys:activity:remove')")
    @Log(title = "奖励活动", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(awardActivityService.deleteAwardActivityByIds(ids));
    }
}
